/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.dengues.model.database.impl;

import java.util.Collection;

import org.dengues.model.database.DBColumn;
import org.dengues.model.database.DBTable;
import org.dengues.model.database.DatabasePackage;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>DB Table</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.dengues.model.database.impl.DBTableImpl#getColumns <em>Columns</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DBTableImpl#isOnlyRead <em>Only Read</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DBTableImpl extends DiagramChildImpl implements DBTable {
    /**
     * The cached value of the '{@link #getColumns() <em>Columns</em>}' containment reference list.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getColumns()
     * @generated
     * @ordered
     */
    protected EList columns;

    /**
     * The default value of the '{@link #isOnlyRead() <em>Only Read</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #isOnlyRead()
     * @generated
     * @ordered
     */
    protected static final boolean ONLY_READ_EDEFAULT = false;

    /**
     * The cached value of the '{@link #isOnlyRead() <em>Only Read</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #isOnlyRead()
     * @generated
     * @ordered
     */
    protected boolean onlyRead = ONLY_READ_EDEFAULT;

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    protected DBTableImpl() {
        super();
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    protected EClass eStaticClass() {
        return DatabasePackage.Literals.DB_TABLE;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public EList getColumns() {
        if (columns == null) {
            columns = new EObjectContainmentWithInverseEList(DBColumn.class, this, DatabasePackage.DB_TABLE__COLUMNS, DatabasePackage.DB_COLUMN__TABLE);
        }
        return columns;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public boolean isOnlyRead() {
        return onlyRead;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setOnlyRead(boolean newOnlyRead) {
        boolean oldOnlyRead = onlyRead;
        onlyRead = newOnlyRead;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, DatabasePackage.DB_TABLE__ONLY_READ, oldOnlyRead, onlyRead));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case DatabasePackage.DB_TABLE__COLUMNS:
                return ((InternalEList)getColumns()).basicAdd(otherEnd, msgs);
        }
        return super.eInverseAdd(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case DatabasePackage.DB_TABLE__COLUMNS:
                return ((InternalEList)getColumns()).basicRemove(otherEnd, msgs);
        }
        return super.eInverseRemove(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public Object eGet(int featureID, boolean resolve, boolean coreType) {
        switch (featureID) {
            case DatabasePackage.DB_TABLE__COLUMNS:
                return getColumns();
            case DatabasePackage.DB_TABLE__ONLY_READ:
                return isOnlyRead() ? Boolean.TRUE : Boolean.FALSE;
        }
        return super.eGet(featureID, resolve, coreType);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void eSet(int featureID, Object newValue) {
        switch (featureID) {
            case DatabasePackage.DB_TABLE__COLUMNS:
                getColumns().clear();
                getColumns().addAll((Collection)newValue);
                return;
            case DatabasePackage.DB_TABLE__ONLY_READ:
                setOnlyRead(((Boolean)newValue).booleanValue());
                return;
        }
        super.eSet(featureID, newValue);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void eUnset(int featureID) {
        switch (featureID) {
            case DatabasePackage.DB_TABLE__COLUMNS:
                getColumns().clear();
                return;
            case DatabasePackage.DB_TABLE__ONLY_READ:
                setOnlyRead(ONLY_READ_EDEFAULT);
                return;
        }
        super.eUnset(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public boolean eIsSet(int featureID) {
        switch (featureID) {
            case DatabasePackage.DB_TABLE__COLUMNS:
                return columns != null && !columns.isEmpty();
            case DatabasePackage.DB_TABLE__ONLY_READ:
                return onlyRead != ONLY_READ_EDEFAULT;
        }
        return super.eIsSet(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public String toString() {
        if (eIsProxy()) return super.toString();

        StringBuffer result = new StringBuffer(super.toString());
        result.append(" (onlyRead: ");
        result.append(onlyRead);
        result.append(')');
        return result.toString();
    }

} //DBTableImpl
